#include <bits/stdc++.h>
using namespace std;

typedef long long int LLI;
typedef vector<pair<int,int> > vpii;
#define mp make_pair
#define pb push_back

vpii adjList[100000];
LLI d[100000];
int parent[100000][17],parenti[100000],depth[100000];
int doDFS(int u,int p,int d) {
    parent[u][0] = p,depth[u] = d;
    for (auto [v,i]: adjList[u]) {
        if (v != p) parenti[v] = i,doDFS(v,u,d+1);
    }
    return 0;
}
int logn;
int lca(int u,int v) {
    int i;
    if (depth[u] < depth[v]) swap(u,v);
    for (i = logn-1; i >= 0; i--) {
        if ((parent[u][i] != -1) && (depth[parent[u][i]] >= depth[v])) u = parent[u][i];
    }
    if (u == v) return u;
    for (i = logn-1; i >= 0; i--) {
        if (parent[u][i] != parent[v][i]) u = parent[u][i],v = parent[v][i];
    }
    return parent[u][0];
}
int lcas[100000],bit[100000];
LLI ans[100000],w[100000];
int main() {
    int i;
    int n,u,v;
    scanf("%d",&n);
    for (i = 0; i < n-1; i++) {
        scanf("%d %d",&u,&v);
        u--,v--;
        adjList[u].pb(mp(v,i));
        adjList[v].pb(mp(u,i));
    }
    for (i = 0; i < n-1; i++) scanf("%lld",&d[i]);

    int j;
    doDFS(0,-1,0);
    for (i = 1; (1 << i) < n; i++) {
        for (j = 0; j < n; j++) {
            if (parent[j][i-1] != -1) parent[j][i] = parent[parent[j][i-1]][i-1];
            else parent[j][i] = -1;
        }
    }
    logn = i;
    for (i = 0; i < n-1; i++) lcas[i] = lca(i,i+1);

    for (i = 0; i < 57; i++) {
        bit[0] = 0;
        for (j = 0; j < n-1; j++) bit[j+1] = bit[j]^(d[j] & 1);
        for (j = 0; j < n-1; j++) d[j] = (d[j]-bit[j]-bit[j+1]+2*bit[lcas[j]])/2;
        for (j = 0; j < n; j++) ans[j] |= ((LLI) bit[j] << i);
    }
    for (i = 0; i < n-1; i++) {
        if (d[i] != 0) {
            printf("-1\n");
            return 0;
        }
    }
    for (i = 1; i < n; i++) {
        w[parenti[i]] = ans[i]-ans[parent[i][0]];
        if (w[parenti[i]] <= 0) {
            printf("-1\n");
            return 0;
        }
    }
    for (i = 0; i < n-1; i++) printf("%lld\n",w[i]);

    return 0;
}